package Model;

import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.FloatControl;
import javax.sound.sampled.Line;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.Port;


public class Volume {

	 public static void setVolume(float value){
		 if (AudioSystem.isLineSupported(Port.Info.SPEAKER)) {
			 try {
                 Line line = AudioSystem.getLine(Port.Info.SPEAKER);                     
                 line.open();
                 FloatControl control =(FloatControl)line.getControl(FloatControl.Type.VOLUME);
                 control.setValue(value);
                 line.close();
         } catch (LineUnavailableException e) {}
		}else if (AudioSystem.isLineSupported(Port.Info.HEADPHONE)){
			try {
                Line line = AudioSystem.getLine(Port.Info.HEADPHONE);                     
                line.open();
                FloatControl control =(FloatControl)line.getControl(FloatControl.Type.VOLUME);
                control.setValue(value);
                line.close();
        } catch (LineUnavailableException e) {}
		}else if (AudioSystem.isLineSupported(Port.Info.LINE_IN)){
			try {
                Line line = AudioSystem.getLine(Port.Info.LINE_IN);                     
                line.open();
                FloatControl control =(FloatControl)line.getControl(FloatControl.Type.VOLUME);
                control.setValue(value);
                line.close();
        } catch (LineUnavailableException e) {}
		}
         
 }
	 
}